#pragma once

#include "CShader.h"
#include "fbo.h"

// todo:
// add render fbo?
// add list of lights that cast shadow?
// callback if viewport size changes?

class ShadowManager
{
public:
	float g_LightPosition[4];

	void init(int screenWid, int screenHei);

	void beginFirstPass();
	void endFirstPass();

	void beginLastPass(float inverseCameraMat[16]);
	void endLastPass();

	FBO frameBufferObject;
	
private:
	bool slowTextureCopyMode;
	GLuint shadowMapTexture;
	float offsetFactor;
	float offsetUnits;

	int screenWid, screenHei;
	int shadowWid, shadowHei;
	CShader g_Shader;

	// These are the light's matrices that need to be stored
	float g_mProjection[16];
	float g_mModelView[16];
	float g_mCameraInverse[16];
	float g_LightView[3];

	void UpdateShadowLightMatrices();
	void CreateRenderTexture(int sizeX, int sizeY, int channels, int type)	;
};